from driver import UART



RS485=UART()
RS485.open("RS485")


#获取温度数据
def get_HC():
    readBuf=bytearray(9) 
    writeBuf=bytearray([0x0B, 0x04, 0x00, 0x00, 0x00, 0x02, 0x71, 0x61]) 
    RS485.write(writeBuf)
    RS485.read(readBuf)
    humidity= ((readBuf[3] * 256) + readBuf[4])/10
    print('humidity',humidity)
    cTemp  = (readBuf[5] * 256 + readBuf[6])/10
    print('cTemp',cTemp)
    return humidity,cTemp


#获取光照数据
def get_light():
    readBuf=bytearray(9) 
    writeBuf=bytearray([0x01,0x03,0x00,0x02,0x00,0x02,0x65,0xCB]) 
    RS485.write(writeBuf)
    RS485.read(readBuf)
    light_intensity= ((readBuf[3] * 256) + readBuf[4])*256*256+((readBuf[5] * 256) + readBuf[6])
    print('light_intensity',light_intensity)
    return light_intensity